﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Cylong.Cache
{
    public interface IRedisService
    {
        #region 单体
        /// <summary>
        /// 更新缓存
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key">缓存建</param>
        /// <param name="t">缓存值</param> 
        /// <remarks>更新缓存</remarks>
        /// <returns></returns>
        bool Update<T>(string key, T t);
        /// <summary>
        /// 设置过期缓存
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key">缓存建</param>
        /// <param name="t">缓存值</param>
        /// <param name="timeout">过期时间，单位秒。0：默认过期时间</param>
        /// <remarks>根据传入的key修改一条记录的值，当key不存在则添加</remarks>
        /// <returns></returns>
        bool Write<T>(string key, T t, TimeSpan expireTime);
        /// <summary>
        /// 获取
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key"></param>
        /// <returns></returns>
        T Get<T>(string key);

        /// <summary>
        /// 移除缓存
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        bool Remove(string key);


        #endregion

        #region String
        #endregion

        #region  List
        /// <summary>
        /// 添加一个项到内部的List 
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key"></param>
        /// <param name="t"></param>
        void List_Add<T>(string key, T t);

        /// <summary>
        /// 根据IEnumerable数据添加链表
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="listId"></param>
        /// <param name="values"></param>
        /// <param name="timeout">秒</param>
        void AddList<T>(string listId, IEnumerable<T> values, int timeout = 0);

        /// <summary>
        /// 根据ListId获取泛型值。
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key">ListID</param>
        /// <returns></returns>
        List<T> List_GetList<T>(string key);

        /// <summary>
        /// 移除指定ListId的内部List<T>中第二个参数值相等的那一项
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key"></param>
        /// <param name="t"></param>
        /// <returns></returns>
        bool List_Remove<T>(string key, T t);
        #endregion

        #region  Hash

        #region 写入
        /// <summary>
        /// 向hashid集合中添加key/value
        /// </summary>       
        bool SetEntryInHash(string hashid, string key, string value);

        /// <summary>
        /// 如果hashid集合中存在key/value则不添加返回false，如果不存在在添加key/value,返回true
        /// </summary>
        bool SetEntryInHashIfNotExists(string hashid, string key, string value);

        /// <summary>
        /// 存储对象T t到hash集合中
        /// </summary>
        void StoreAsHash<T>(T t);

        /// <summary>
        /// 获取hashid数据集中，key的value数据
        /// </summary>
        string GetValueFromHash(string hashid, string key);

        /// <summary>
        /// 存储数据到hash表
        /// </summary>
        bool Hash_Set<T>(string hashid, string key, T t);
        #endregion

        /// <summary>
        /// 获取所有hashid数据集的key/value数据集合
        /// </summary>
        Dictionary<string, string> GetAllEntriesFromHash(string hashid);
        /// <summary>
        /// 获取hashid数据集中的数据总数
        /// </summary>
        long GetHashCount(string hashid);
        /// <summary>
        /// 判断hashid数据集中是否存在key的数据
        /// </summary>
        bool Hash_Exist<T>(string hashid, string key);
        /// <summary>
        /// 删除hashid数据集中的key数据
        /// </summary>
        bool RemoveEntryFromHash(string hashid, string key);

        /// <summary>
        /// 获取hashid数据集中，key的value数据
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="hashId"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        T Hash_Get<T>(string hashId, string key);

        /// <summary>
        /// 获取整个hash的数据
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key"></param>
        /// <returns></returns>
        List<T> Hash_GetAll<T>(string hashId);

        #endregion

        #region  Set
        /// <summary>
        /// 随机获取key集合中的一个值
        /// </summary>
        string GetRandomItemFromSet(string key);

        HashSet<string> GetAllItemsFromSet(string key);

        /// <summary>
        /// key集合中添加value值
        /// </summary>
        void AddItemToSet(string key, string value);

        /// <summary>
        /// Set添加集合
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key"></param>
        /// <param name="t"></param>
        void Set_Add<T>(string key, T t);
        /// <summary>
        /// 获取所有key集合的值
        /// </summary>
        T GetRandomItemFromSets<T>(string key);

        /// <summary>
        /// Set删除
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key"></param>
        void Set_Remove<T>(string key);

        #endregion

        #region SortedSet
        #endregion
    }
}
